package com.monitor.zkm.util;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;

public class FormatSize {

    public static String formSize(String val) {
        if (StrUtil.endWithIgnoreCase(val, "g")) {
            String newVal = val.substring(0, val.length() - 1);
            return String.format("%.2f MB", Convert.toDouble(newVal, 0D) / 1024 / 1024);
        }
        if (StrUtil.endWithIgnoreCase(val, "m")) {
            String newVal = val.substring(0, val.length() - 1);
            return Convert.toLong(newVal, 0L) / 1024 + " MB";
        }
        if (StrUtil.endWithIgnoreCase(val,"byte")){
            String newVal = val.substring(0, val.length() - 4);
            return String.format("%.2f MB",Convert.toDouble(newVal,0.0) / 1024.0 / 1024.0);
        }
        return Convert.toLong(val, 0L) / 1024 + " MB";
    }

}
